package com.ruoyi.web.controller.personnel;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.domain.Personnel;
import com.ruoyi.personnel.domain.PersonnelExcel;
import com.ruoyi.personnel.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/personnel")
public class PersonnelController extends BaseController {

    @Autowired
    private PersonnelService personnelService;

    @GetMapping("/queryByPage")
    public TableDataInfo queryByPage(Personnel personnel) {
        startPage();
        return getDataTable(personnelService.queryByPage(personnel));
    }

    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody Personnel personnel) {
        return success(personnelService.insert(personnel));
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody Personnel personnel) {
        return success(personnelService.update(personnel));
    }

    @DeleteMapping("/delByIds/{ids}")
    public AjaxResult delByIds(@PathVariable Long[] ids) {
        return success(personnelService.delByIds(ids));
    }

    @GetMapping("/getPersonnelById")
    public AjaxResult getPersonnelById(int id) {
        return success(personnelService.getPersonnelById(id));
    }

    //导入
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        return success(personnelService.importData(file));
    }

    //导出
    @PostMapping("/export")
    public void export(HttpServletResponse response,Personnel personnel){
        personnelService.export(response, personnel);
    }

    //下载模板
    @PostMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletResponse response){
        List<PersonnelExcel> list = new ArrayList<PersonnelExcel>();
        ExcelUtil<PersonnelExcel> util = new ExcelUtil<PersonnelExcel>(PersonnelExcel.class);
        util.exportExcel(response, list, "品管师列表", "");
    }
}
